package com.fenghongzhang.day005;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


/**
 * A simple {@link Fragment} subclass.
 */
public class SendFragment extends Fragment {
    private EditText fgEdit;
    private Button btn;
    public SendFragment() {
        // Required empty public constructor
    }


    //1
    public interface MyListener{
        void send(String s);
    }
    //2
    private MyListener myListener;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_send, container, false);
        fgEdit = (EditText) inflate.findViewById(R.id.fg_edit);
        btn = (Button) inflate.findViewById(R.id.btn);
        //3
        myListener = (MyListener) getActivity();

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String string = fgEdit.getText().toString();
                //发送
                //4
                myListener.send(string);
            }
        });
        return inflate;
    }
}
